// @ts-nocheck
import "./core/polyfill";

import { plugin } from "./core/plugin";
import "./core/pluginRegister";
import { createHistory } from "./core/history";
import { ApplyPluginsType } from "/Users/Aladdin/Downloads/travel-card-github/node_modules/umi/node_modules/@umijs/runtime";
import { renderClient } from "/Users/Aladdin/Downloads/travel-card-github/node_modules/@umijs/renderer-react";
import { getRoutes } from "./core/routes";

import "../global.css";

const getClientRender = (args: { hot?: boolean; routes?: any[] } = {}) =>
  plugin.applyPlugins({
    key: "render",
    type: ApplyPluginsType.compose,
    initialValue: () => {
      const opts = plugin.applyPlugins({
        key: "modifyClientRenderOpts",
        type: ApplyPluginsType.modify,
        initialValue: {
          routes: args.routes || getRoutes(),
          plugin,
          history: createHistory(args.hot),
          isServer: process.env.__IS_SERVER,
          rootElement: "root",
          defaultTitle: `行程卡纪念版`,
        },
      });
      return renderClient(opts);
    },
    args,
  });

const clientRender = getClientRender();
export default clientRender();

window.g_umi = {
  version: "3.5.21",
};

// hot module replacement
// @ts-ignore
if (module.hot) {
  // @ts-ignore
  module.hot.accept("./core/routes", () => {
    const ret = require("./core/routes");
    if (ret.then) {
      ret.then(({ getRoutes }) => {
        getClientRender({ hot: true, routes: getRoutes() })();
      });
    } else {
      getClientRender({ hot: true, routes: ret.getRoutes() })();
    }
  });
}
